﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AmazonDynamoDBStub.Extensions
{
    [TestClass]
    public class AttributeValueExtensionsTest
    {
        private AttributeValue S;
        private AttributeValue N;
        private AttributeValue B;
        private AttributeValue SS;
        private AttributeValue NS;
        private AttributeValue BS;

        [TestInitialize]
        public void Initialize()
        {
            var binary = new MemoryStream(new byte[] { 0x41, 0x42, 0x43 });
            this.S = new AttributeValue { S = "str" };
            this.N = new AttributeValue { N = "100" };
            this.B = new AttributeValue { B = binary };
            this.SS = new AttributeValue { SS = new List<string> { "str1", "str2", "str3" } };
            this.NS = new AttributeValue { NS = new List<string> { "111", "222", "333" } };
            this.BS = new AttributeValue { BS = new List<MemoryStream> { binary, binary, binary } };
        }

        [TestMethod]
        public void ShouldReturnAttributeValueAsExpectedStringValue()
        {
            var actual = S.GetAttributeValue();

            Assert.AreEqual("str", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeValueAsExpectedNumericValue()
        {
            var actual = N.GetAttributeValue();

            Assert.AreEqual("100", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeValueAsExpectedEncodedBase64Value()
        {
            var expected = "QUJD";

            var actual = B.GetAttributeValue();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeValueAsExpectedStringArrayValue()
        {
            var actual = SS.GetAttributeValue();

            Assert.AreEqual("[\"str1\",\"str2\",\"str3\"]", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeValueAsExpectedNumericArrayValue()
        {
            var actual = NS.GetAttributeValue();

            Assert.AreEqual("[\"111\",\"222\",\"333\"]", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeValueAsExpectedEncodedBase64ArrayValue()
        {
            var actual = BS.GetAttributeValue();

            Assert.AreEqual("[\"QUJD\",\"QUJD\",\"QUJD\"]", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeTypeAsS()
        {
            var actual = S.GetAttributeType();

            Assert.AreEqual("S", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeTypeAsN()
        {
            var actual = N.GetAttributeType();

            Assert.AreEqual("N", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeTypeAsB()
        {
            var actual = B.GetAttributeType();

            Assert.AreEqual("B", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeTypeAsSS()
        {
            var actual = SS.GetAttributeType();

            Assert.AreEqual("SS", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeTypeAsNS()
        {
            var actual = NS.GetAttributeType();

            Assert.AreEqual("NS", actual);
        }

        [TestMethod]
        public void ShouldReturnAttributeTypeAsBS()
        {
            var actual = BS.GetAttributeType();

            Assert.AreEqual("BS", actual);
        }
    }
}
